package xing.example.config.editor;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyEditorRegistrySupport;
import org.springframework.beans.TypeConverter;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.stereotype.Component;
import xing.example.bean.A;
import xing.example.editor.AEditor;

/**
 * 在单纯的 Spring Boot Starter 中，还可以这么做。（已知实际类型为 SimpleTypeConverter ）
 * <p>
 * 显然假如被其他的 TypeConverter 替换，就不能用了.
 * <p>
 * 本身应该就不是其正确用法。接口没给，本身应该按接口方式使用。
 *
 * @author xing
 * @date 2023/2/15 20:42:38
 */
//@Component
@Deprecated
public class RegisterCustomEditors5 implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
        TypeConverter typeConverter = beanFactory.getTypeConverter();
        if (typeConverter instanceof PropertyEditorRegistrySupport editorRegistrySupport) {
            editorRegistrySupport.registerCustomEditor(A.class, new AEditor());
        }
    }
}
